package com.itheima.service.impl;

import cn.hutool.core.util.ArrayUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.entity.Members;
import com.itheima.mapper.MembersMapper;
import com.itheima.service.MembersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MembersServiceImpl implements MembersService {
    @Autowired
    private MembersMapper membersMapper;

    @Override
    public PageInfo<Members> findByPage(int pageNum, int pageSize, Integer cid, String keyword) {
        PageHelper.startPage(pageNum, pageSize);
        keyword = (keyword != null ? keyword.trim() : keyword);
        List<Members> list = membersMapper.findByPage(cid, keyword);

        return new PageInfo<>(list);
    }

    @Override
    public Members findById(Integer id) {
        return membersMapper.findById(id);
    }

    @Override
    public List<Members> findAll() {
        return membersMapper.findAll();
    }

    @Override
    public void save(Members members) {
        membersMapper.save(members);
    }

    @Override
    public void update(Members members) {
        membersMapper.update(members);
    }

    @Override
    public void deleteById(Integer id) {
        membersMapper.deleteById(id);
    }

    @Override
    public void deleteBatch(Integer[] ids) {
        if (ArrayUtil.isNotEmpty(ids)) {
            membersMapper.deleteByIds(ids);
        }
    }
}
